package cn.zhiquxing.service.impl;

import cn.zhiquxing.domain.*;
import cn.zhiquxing.pipeline.ProcessController;
import cn.zhiquxing.service.SendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;


@Service
public class SendServiceImpl implements SendService {
    
    @Autowired
    @Qualifier("apiProcessController")
    private ProcessController processController;
    
    @Override
    public SendResponse send(SendRequest sendRequest) {
        if (Objects.isNull(sendRequest)) {
            return new SendResponse("A0001", "发送参数为空", null);
        }
        SendTaskModel sendTaskModel = SendTaskModel.builder()
                .messageTemplateId(sendRequest.getMessageTemplateId())
                .messageParamList(Collections.singletonList(sendRequest.getMessageParam()))
                .build();
        ProcessContext<ProcessModel> context = ProcessContext.builder()
                .code(sendRequest.getCode())
                .processModel(sendTaskModel)
                .needBreak(false)
                .response(BasicResultVO.success()).build();

        ProcessContext process = processController.process(context);
        return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg(), (List<SimpleTaskInfo>)process.getResponse().getData());
    }

    @Override
    public SendResponse batchSend(SendRequest sendRequest) {
        return null;
    }
}
